package tp1;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.io.Reader;

public class CopierClasse {

	private File source;
	private File dest;

	public CopierClasse() {
		super();
	}
// java.class
	public CopierClasse(String source, String dest) {
		super();
		setSource(new File(source));
		setDest(new File(dest));
	}

	public void copier() {
		boolean isClass = dest
				.getName()
				.substring(dest.getName().lastIndexOf("."), dest.getName().length())
				.equals(".class");
		if (source.exists()) {
			if (dest.exists()) {
				System.out.println("le fichier de destination existe");
			} else {
				if (isClass) {
					// copier le fichier
					BufferedReader br = null;
					BufferedWriter bw = null;
					try {
						br = new BufferedReader(new FileReader(source));
						bw = new BufferedWriter(new FileWriter(dest));
						dest.mkdirs();

						while (br.ready()) {
							bw.write(br.readLine());
						}

					} catch (FileNotFoundException e) {
						e.printStackTrace();
					} catch (IOException e) {
						e.printStackTrace();
					} finally {
						try {
							bw.close();
							br.close();
						} catch (IOException e) {
							e.printStackTrace();
						}
					}
				} else {
					System.out.println("le fichier n'est pas un .class");
				}
			}

		} else {
			System.out.println("le fichier source n'existe pas");
		}

	}

	public File getDest() {
		return dest;
	}

	public void setSource(File source) {
		this.source = source;
	}

	public File getSource() {
		return source;
	}

	public void setDest(File dest) {
		this.dest = dest;
	}

	public static void main(String[] args) {
	
	}
	

}
